
//
//	Top Level - 2011 Jully 4th
//	
//	The top level contains the core ActionScript classes and global functions.
//	Most of the classes and their prototypes are already implemented in Javascript.
//
//-------------------------------------------------------------------------------------------------


//	Trace
//-------------------------------------------------------------------------------------------------

this.trace = (function() {
	if(console && console.log) {
		return function() {
			console.log.apply(console, arguments);
		};
	} else {
		return function() {
			alert(ArrayJoin.call(arguments, " "));
		};
	}
}());


//	Array
//-------------------------------------------------------------------------------------------------

Array.CASEINSENSITIVE = 1;
Array.DESCENDING = 2;
Array.UNIQUESORT = 4;
Array.RETURNINDEXEDARRAY = 8;
Array.NUMERIC = 16;

Array.prototype._sort = Array.prototype.sort;
Array.prototype.sort = function(compareFunction, sortOptions) {
	return this._sort(compareFunction);
};

if(typeof Array.prototype.sortOn != 'function') Array.prototype.sortOn = function(fieldName, options) {
	
};


//
//	Class
//
//	Based on John Resig's inheritance technique
//	http://ejohn.org/blog/simple-javascript-inheritance/
//
//	Examples: https://gist.github.com/1062971
//
//-------------------------------------------------------------------------------------------------

(function() {
	
	var initialize;
	
	function Class() {}
	
	Class.extend = function(classObject) {
		
		initialize = false;
		
		var key, prop,
		classFunctions = {},
		classGetters = {},
		classSetters = {},
		classPrototype = new this();
		
		initialize = true;
		
		for(key in classObject) {
			prop = xb.Object.lookupProperty.call(classObject, key);
			if(prop) {
				xb.Object.defineProperty.call(classPrototype, key, prop);
				if(typeof prop.value == 'function') classFunctions[key] = prop.value;
				if(typeof prop.get == 'function') classGetters[key] = prop.get;
				if(typeof prop.set == 'function') classSetters[key] = prop.set;
			}
		}
		
		function Class() {
			if(initialize) {
				this.init.apply(this, arguments);
			}
		}
		
		classPrototype.constructor = Class;
		
		Class.prototype = classPrototype;
		Class.fn = classFunctions;
		Class.get = classGetters;
		Class.set = classSetters;
		Class.extend = arguments.callee;
		
		return Class;
		
	};
	
	Class.prototype = {
		constructor: Class,
		init: function() {}
	};
	
	this.Class = Class;

}());


//	Vector
//
//	The Vector class lets you access and manipulate a vector — an array whose elements all have the
//	same data type.
//-------------------------------------------------------------------------------------------------

if(typeof this.Vector != 'function') {

	this.Vector = function(baseType, length, fixed) {
		Array.call(this);
		
		this._baseType = dataType;
		this.length = Number(length);
		this.fixed = Boolean(fixed);
	};
	
	Vector.prototype = new Array();
	
	
	
}
